import { defineStore } from 'pinia'

export const useAppStore = defineStore('app', {
  state: () => ({
    // 用户信息
    userInfo: {
      id: 1,
      username: 'admin',
      avatar: '',
      roles: ['admin']
    },

    // 侧边栏状态
    sidebar: {
      opened: true,
      withoutAnimation: false
    },

    // 设备类型
    device: 'desktop',

    // 权限菜单
    permissions: []
  }),

  actions: {
    // 切换侧边栏
    toggleSidebar() {
      this.sidebar.opened = !this.sidebar.opened
      this.sidebar.withoutAnimation = false
    },

    // 关闭侧边栏
    closeSidebar(withoutAnimation) {
      this.sidebar.opened = false
      this.sidebar.withoutAnimation = withoutAnimation
    },

    // 切换设备
    toggleDevice(device) {
      this.device = device
    },

    // 设置权限
    setPermissions(permissions) {
      this.permissions = permissions
    }
  }
})
